<template>
  <div class="news">
    <div class="block">
      <el-card class="box-card" :body-style="{backgroundColor: '#fafafa' }">
        <div slot="header" class="box-head">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item class="c-text">
              首页
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="input">
          <el-input placeholder="请输入搜索关键词" v-model="input">
            <el-select v-model="select" slot="prepend" class="input-text">
              <el-option label="全部文章" value="0"></el-option>
              <el-option label="防诈知识" value="1"></el-option>
              <el-option label="真实案例" value="2"></el-option>
              <el-option label="用户分享" value="3"></el-option>
            </el-select>
            <el-button class="input-button" slot="append" icon="el-icon-search" @click="search"></el-button>
          </el-input>
        </div>
        <el-row :gutter="50">
          <el-col :span="8">
            <div class="grid-content bg-purple">
              <el-card class="b-card" :body-style="{ padding: '0px',}" shadow="hover" @click.native="cardclick(1)">
                <img src="../../assets/article/knowledge2.png" class="image">
                <div class="b-text">
                  <span>防诈知识</span>
                </div>
              </el-card>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-c ontent bg-purple">
              <el-card class="b-card" :body-style="{ padding: '0px' }" shadow="hover" @click.native="cardclick(2)">
                <img src="../../assets/article/case2.png" class="image">
                <div class="b-text">
                  <span>真实案例</span>
                </div>
              </el-card>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-content bg-purple">
              <el-card class="b-card" :body-style="{padding: '0px' }" shadow="hover" @click.native="cardclick(3)">
                <img src="../../assets/article/share2.png" class="image">
                <div class="b-text">
                  <span>用户分享</span>
                </div>
              </el-card>
            </div>
          </el-col>
        </el-row>
      </el-card>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import axios from "axios";

export default {
  name: "News",
  data() {
    return {
      input: '',
      select: '0',
    };
  },
  mounted() {
    this.load();
  },
  methods: {
    load(){
    },
    cardclick(id){
      if(id === 1) {
        this.$router.push("/article/knowledge")
      }
      else if(id === 2){
        this.$router.push("/article/case")
      }
      else {
        this.$router.push("/article/share")
      }
    },
    search() {
      if(this.select < '0' || this.select > '3') {
        // 判断文章搜索类型是否正确
        this.$message({
          showClose: true,
          type: "error",
          message: "搜索类型获取失败！"
        })
        //返回错误信息
      } else if(this.input === '') {
        // 判断输入信息是否为空
        this.$message({
          showClose: true,
          type: "error",
          message: "请输入搜索关键词！"
        })
        //返回错误信息
      } else {
        sessionStorage.setItem("type", JSON.stringify(this.select))
        sessionStorage.setItem("str", JSON.stringify(this.input))
        // 创建本地存储
        this.$router.push("/article/search")
        // 跳转页面
      }
    }
  }
}
</script>

<style scoped>
.news{
  width: 100%;
  min-height: 666px;
}

.block{
  width: 80%;
  padding-top: 20px;
  position: relative;
  left: 50%;
  transform: translate(-50%, 0%);
  /*box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);*/
}

.input {
  padding: 10px 20px;
  position: relative;
  left: 50%;
  transform: translate(-50%, 0%);
}

.input-text {
  background-color: #354e66;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  font-weight: bold;
  color: #f9bf4b;
  font-size: 16px;
}

.input-button{
  background-color: #354e66 !important;
  border-top-left-radius: 0px;
  border-bottom-left-radius: 0px;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  color: #f9bf4b !important;
}

.el-select{
  width: 110px;
}

.input-with-select .el-input-group__prepend {
  background-color: #fff;
}

.el-row {
  padding: 20px;
}

.el-col {
  border-radius: 40px;
}

.box-card{
  background-color: #354e66;
}

/deep/ .el-breadcrumb__inner {
  color: #f9bf4b !important;
  font-weight: bold !important;
}

.c-text {
  font-size: 17px;
  color: #f9bf4b;
}

.b-card {
}

.image {
  width: 100%;
  display: block;
}

.b-text {
  padding: 14px;
  background: #354e66;
  color: #f9bf4b;
  font-size: 17px;
  font-weight: bold;
}

.clearfix:after {
  clear: both
}

.b-card{
  animation-duration: 1s;
  animation-name: slidein;
}

@keyframes slidein {
  from {
    margin-top: 50%;
  }
  to {
    margin-top: 0%;
  }
}
</style>